package cn.yh.register.user.controller;

import cn.yh.register.common.result.Result;
import cn.yh.register.model.user.UserInfo;
import cn.yh.register.user.service.UserInfoService;
import cn.yh.register.vo.user.UserInfoQueryVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@Api(tags = "用户管理接口")
@RestController
@RequestMapping("/admin/user")
public class UserController {
    @Autowired
    UserInfoService userInfoService;
    @ApiOperation("用户列表（条件查询带分页）")
    @GetMapping("{page}/{limit}")
    public Result<Page<UserInfo>> list(@PathVariable Long page,
                       @PathVariable Long limit,
                       UserInfoQueryVo userInfoQueryVo) {

        Page<UserInfo> userInfoPage = userInfoService.findByPage(new Page<UserInfo>(page, limit), userInfoQueryVo);
        return Result.ok(userInfoPage);
    }

    @ApiOperation(value = "锁定")
    @GetMapping("lock/{userId}/{status}")
    public Result<?> lock(
            @PathVariable("userId") Long userId,
            @PathVariable("status") Integer status){
        userInfoService.lock(userId, status);
        return Result.ok();
    }

    @ApiOperation("用户详情")
    @GetMapping("show/{userId}")
    public Result show(@PathVariable Long userId) {
        Map<String,Object> map = userInfoService.showUser(userId);
        return Result.ok(map);
    }

    @ApiOperation("认证审批")
    @GetMapping("approval/{userId}/{authStatus}")
    public Result approval(@PathVariable Long userId,@PathVariable Integer authStatus) {
        userInfoService.approval(userId,authStatus);
        return Result.ok();
    }

}
